/**
 * Copyright (c) 2011-2014, hubin (243194995@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package wang.leq.kissospringmvc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.kisso.SSOHelper;
import com.baomidou.kisso.SSOToken;
import com.baomidou.kisso.web.waf.request.WafRequestWrapper;

/**
 * 登录
 */
@Controller
public class LoginController extends BaseController {

	@RequestMapping("/login")
	public String login( HttpServletRequest request ) {
		SSOToken st = (SSOToken) SSOHelper.getToken(request);
		if ( st != null ) {
			return redirectTo("/index.html");
		}
		return "login";
	}


	@RequestMapping("/loginpost")
	public String loginpost( HttpServletRequest request, HttpServletResponse response ) {
		//生成环境需要过滤sql注入
		WafRequestWrapper req = new WafRequestWrapper(request);
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		if ( "kisso".equals(username) && "123".equals(password) ) {
			SSOToken st = new SSOToken();
			st.setUserId(12306);
			SSOHelper.authSSOCookie(request, response, st);
			return redirectTo("/index.html");
		}
		return "login";
	}
}
